{extend name="common/layout" /}
{block name="main"}
<div class="admin-main layui-anim layui-anim-upbit">
    <div class="padding30">
       <h3 class="page-box-title">{:lang('Mailbox Config')}</h3>
    </div>
     <div class="layui-form-box">
        <form class="layui-form">
            <div class="layui-form-item">
                <label class="layui-form-label">{:lang('Server')}</label>
                <div class="layui-input-6">
                    <input type="text" lay-verify="required" name="smtp_server" placeholder="{:lang('Server')}" value="{$info.smtp_server}" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">{:lang('Server Port')}</label>
                <div class="layui-input-6">
                    <input type="text" lay-verify="required" name="smtp_port" placeholder="{:lang('Server Port')}" value="{$info.smtp_port}" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">{:lang('Sender')}</label>
                <div class="layui-input-6">
                    <input type="text" name="smtp_user" lay-verify="required" placeholder="{:lang('From Address')}" value="{$info.smtp_user}" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">{:lang('Account Password')}</label>
                <div class="layui-input-6">
                    <input type="text" name="smtp_pwd" lay-verify="required" placeholder="{:lang('Account Password')}" value="{$info.smtp_pwd}" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">{:lang('Test mail')}</label>
                <div class="layui-input-6">
                    <input type="text" name="test_eamil" id="test_eamil" placeholder="{:lang('Test receiving mail address')}" value="{$info.test_eamil}" class="layui-input">
                </div>
            </div>
            </br></br>
        <div class="layui-form-item">
            <label class="layui-form-label layui-form-label-no"></label>
            <div class="layui-input-6 pleft22">
                <button type="button" class="layui-btn" lay-submit="" lay-filter="submit">{:lang('Submit')}</button>
                    <button type="button" class="layui-btn layui-btn-primary" id="trySend">{:lang('Sending')}</button>
            </div>
            
        </div>
           
        </form>
    </div>
</div>
{/block}
{block name="footer"}
<script>
    layui.use(['form', 'layer'], function () {
        var form = layui.form,layer = layui.layer,$= layui.jquery;
        //发送测试邮件
        $('#trySend').click(function(){
            loading =layer.load(1, {shade: [0.1,'#fff']});
            var email = $('#test_eamil').val();
            $.post("{:url('trySend')}",{email:email},function(res){
                layer.close(loading);
                if(res.code > 0){
                    layer.msg(res.msg,{time:1800});
                }else{
                    layer.msg(res.msg,{time:1800});
                }
            });
        });
        //提交监听
        form.on('submit(submit)', function (data) {
            loading =layer.load(1, {shade: [0.1,'#fff']});
            $.post("{:url('system/email')}",data.field,function(res){
                layer.close(loading);
                if(res.code > 0){
                    layer.msg(res.msg,{icon: 1, time: 1000},function(){
                        location.href = res.url;
                    });
                }else{
                    layer.msg(res.msg,{icon: 2, time: 1000});
                }
            });
        })
    })
</script>
{/block}